package com.fr.privilege.authentication;

import com.fr.base.core.ComparatorUtils;
import com.fr.privilege.authority.Authority;
import com.fr.privilege.user.User;
import java.security.Principal;

public abstract class AbstractAuthentication
  implements Authentication
{
  private static final long serialVersionUID = 5846413362332382520L;
  private Object details;
  private Authority[] authorities;
  private boolean authenticated = false;

  public void setAuthorities(Authority[] paramArrayOfAuthority)
  {
    this.authorities = paramArrayOfAuthority;
  }

  public void setDetails(Object paramObject)
  {
    this.details = paramObject;
  }

  public Authority[] getAuthorities()
  {
    if (this.authorities == null)
      return new Authority[0];
    Authority[] arrayOfAuthority = new Authority[this.authorities.length];
    System.arraycopy(this.authorities, 0, arrayOfAuthority, 0, this.authorities.length);
    return arrayOfAuthority;
  }

  public Object getDetails()
  {
    return this.details;
  }

  public boolean isAuthenticated()
  {
    return this.authenticated;
  }

  public void setAuthenticated(boolean paramBoolean)
  {
    this.authenticated = paramBoolean;
  }

  public String getName()
  {
    if (getPrincipal() instanceof User)
      return ((User)getPrincipal()).getUsername();
    if (getPrincipal() instanceof Principal)
      return ((Principal)getPrincipal()).getName();
    return ((getPrincipal() == null) ? "" : getPrincipal().toString());
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof AbstractAuthentication) && (ComparatorUtils.equals(((AbstractAuthentication)paramObject).authorities, this.authorities)) && (ComparatorUtils.equals(((AbstractAuthentication)paramObject).details, this.details)) && (ComparatorUtils.equals(((AbstractAuthentication)paramObject).getCredentials(), getCredentials())) && (ComparatorUtils.equals(((AbstractAuthentication)paramObject).getPrincipal(), getPrincipal())) && (((AbstractAuthentication)paramObject).authenticated == this.authenticated));
  }

  public String toString()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append(super.toString()).append(": ");
    localStringBuffer.append("Principal: ").append(getPrincipal()).append("; ");
    localStringBuffer.append("Password: [PROTECTED]; ");
    localStringBuffer.append("Authenticated: ").append(isAuthenticated()).append("; ");
    localStringBuffer.append("Details: ").append(getDetails()).append("; ");
    if (getAuthorities() != null)
    {
      localStringBuffer.append("Granted Authorities: ");
      int i = 0;
      while (true)
      {
        if (i >= getAuthorities().length)
          break label149;
        if (i > 0)
          localStringBuffer.append(", ");
        localStringBuffer.append(getAuthorities()[i].toString());
        ++i;
      }
    }
    localStringBuffer.append("Not granted any authorities");
    label149: return localStringBuffer.toString();
  }
}